<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="省份名" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份名"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="城市名" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市名"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="区域编码" prop="adcode">
        <el-input
          v-model="queryParams.adcode"
          placeholder="请输入区域编码"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-input
          v-model="queryParams.date"
          placeholder="请输入日期"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="星期几" prop="week">
        <el-input
          v-model="queryParams.week"
          placeholder="请输入星期几"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="白天天气现象" prop="dayWeather">
        <el-input
          v-model="queryParams.dayWeather"
          placeholder="请输入白天天气现象"
          clearable
          
        />
      </el-form-item>
      <!-- <el-form-item label="白天天气图片" prop="dayWeatherImg">
        <el-input
          v-model="queryParams.dayWeatherImg"
          placeholder="请输入白天天气图片"
          clearable
          
        />
      </el-form-item> -->
      <el-form-item label="晚上天气现象" prop="nightWeather">
        <el-input
          v-model="queryParams.nightWeather"
          placeholder="请输入晚上天气现象"
          clearable
          
        />
      </el-form-item>
      <!-- <el-form-item label="晚上天气图片" prop="nightWeatherImg">
        <el-input
          v-model="queryParams.nightWeatherImg"
          placeholder="请输入晚上天气图片"
          clearable
          
        />
      </el-form-item> -->
      <el-form-item label="白天温度" prop="dayTemp">
        <el-input
          v-model="queryParams.dayTemp"
          placeholder="请输入白天温度"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="晚上温度" prop="nightTemp">
        <el-input
          v-model="queryParams.nightTemp"
          placeholder="请输入晚上温度"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="白天风向" prop="dayWind">
        <el-input
          v-model="queryParams.dayWind"
          placeholder="请输入白天风向"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="晚上风向" prop="nightWind">
        <el-input
          v-model="queryParams.nightWind"
          placeholder="请输入晚上风向"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="白天风力" prop="dayPower">
        <el-input
          v-model="queryParams.dayPower"
          placeholder="请输入白天风力"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="晚上风力" prop="nightPower">
        <el-input
          v-model="queryParams.nightPower"
          placeholder="请输入晚上风力"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="数据发布的时间" prop="reportTime">
        <el-input
          v-model="queryParams.reportTime"
          placeholder="请输入数据发布的时间"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段1" prop="weatherForecastExtra1">
        <el-input
          v-model="queryParams.weatherForecastExtra1"
          placeholder="请输入备用字段1"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段2" prop="weatherForecastExtra2">
        <el-input
          v-model="queryParams.weatherForecastExtra2"
          placeholder="请输入备用字段2"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段3" prop="weatherForecastExtra3">
        <el-input
          v-model="queryParams.weatherForecastExtra3"
          placeholder="请输入备用字段3"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段4" prop="weatherForecastExtra4">
        <el-input
          v-model="queryParams.weatherForecastExtra4"
          placeholder="请输入备用字段4"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段5" prop="weatherForecastExtra5">
        <el-input
          v-model="queryParams.weatherForecastExtra5"
          placeholder="请输入备用字段5"
          clearable
          
        />
      </el-form-item>
    
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yanjing:forecast:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yanjing:forecast:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yanjing:forecast:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yanjing:forecast:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="forecastList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="省份名" align="center" prop="province" />
      <el-table-column label="城市名" align="center" prop="city" />
      <el-table-column label="区域编码" align="center" prop="adcode" />
      <el-table-column label="日期" align="center" prop="date" width="100px" />
      <el-table-column label="星期几" align="center" prop="week" />
      <el-table-column label="白天天气现象" align="center" prop="dayWeather" />
      <!-- <el-table-column label="白天天气图片" align="center" prop="dayWeatherImg" /> -->
      <el-table-column label="晚上天气现象" align="center" prop="nightWeather" />
      <!-- <el-table-column label="晚上天气图片" align="center" prop="nightWeatherImg" /> -->
      <el-table-column label="白天温度" align="center" prop="dayTemp" />
      <el-table-column label="晚上温度" align="center" prop="nightTemp" />
      <el-table-column label="白天风向" align="center" prop="dayWind" />
      <el-table-column label="晚上风向" align="center" prop="nightWind" />
      <el-table-column label="白天风力" align="center" prop="dayPower" />
      <el-table-column label="晚上风力" align="center" prop="nightPower" />
      <el-table-column label="数据发布的时间" align="center" prop="reportTime" width="200px" />
      <el-table-column label="备用字段1" align="center" prop="weatherForecastExtra1" />
      <el-table-column label="备用字段2" align="center" prop="weatherForecastExtra2" />
      <el-table-column label="备用字段3" align="center" prop="weatherForecastExtra3" />
      <el-table-column label="备用字段4" align="center" prop="weatherForecastExtra4" />
      <el-table-column label="备用字段5" align="center" prop="weatherForecastExtra5" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yanjing:forecast:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yanjing:forecast:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page.sync="queryParams.pageNum"
      v-model:limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预报天气对话框 -->
    <el-dialog :title="title" v-model:visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="省份名" prop="province">
          <el-input v-model="form.province" placeholder="请输入省份名" />
        </el-form-item>
        <el-form-item label="城市名" prop="city">
          <el-input v-model="form.city" placeholder="请输入城市名" />
        </el-form-item>
        <el-form-item label="区域编码" prop="adcode">
          <el-input v-model="form.adcode" placeholder="请输入区域编码" />
        </el-form-item>
        <el-form-item label="日期" prop="date" width = '800'>
          <el-input v-model="form.date" placeholder="请输入日期" />
        </el-form-item>
        <el-form-item label="星期几" prop="week">
          <el-input v-model="form.week" placeholder="请输入星期几" />
        </el-form-item>
        <el-form-item label="白天天气现象" prop="dayWeather">
          <el-input v-model="form.dayWeather" placeholder="请输入白天天气现象" />
        </el-form-item>

        <el-form-item label="晚上天气现象" prop="nightWeather">
          <el-input v-model="form.nightWeather" placeholder="请输入晚上天气现象" />
        </el-form-item>

        <el-form-item label="白天温度" prop="dayTemp">
          <el-input v-model="form.dayTemp" placeholder="请输入白天温度" />
        </el-form-item>
        <el-form-item label="晚上温度" prop="nightTemp">
          <el-input v-model="form.nightTemp" placeholder="请输入晚上温度" />
        </el-form-item>
        <el-form-item label="白天风向" prop="dayWind">
          <el-input v-model="form.dayWind" placeholder="请输入白天风向" />
        </el-form-item>
        <el-form-item label="晚上风向" prop="nightWind">
          <el-input v-model="form.nightWind" placeholder="请输入晚上风向" />
        </el-form-item>
        <el-form-item label="白天风力" prop="dayPower">
          <el-input v-model="form.dayPower" placeholder="请输入白天风力" />
        </el-form-item>
        <el-form-item label="晚上风力" prop="nightPower">
          <el-input v-model="form.nightPower" placeholder="请输入晚上风力" />
        </el-form-item>
        <el-form-item label="数据发布的时间" prop="reportTime">
          <el-input v-model="form.reportTime" placeholder="请输入数据发布的时间" />
        </el-form-item>
        <el-form-item label="备用字段1" prop="weatherForecastExtra1">
          <el-input v-model="form.weatherForecastExtra1" placeholder="请输入备用字段1" />
        </el-form-item>
        <el-form-item label="备用字段2" prop="weatherForecastExtra2">
          <el-input v-model="form.weatherForecastExtra2" placeholder="请输入备用字段2" />
        </el-form-item>
        <el-form-item label="备用字段3" prop="weatherForecastExtra3">
          <el-input v-model="form.weatherForecastExtra3" placeholder="请输入备用字段3" />
        </el-form-item>
        <el-form-item label="备用字段4" prop="weatherForecastExtra4">
          <el-input v-model="form.weatherForecastExtra4" placeholder="请输入备用字段4" />
        </el-form-item>
        <el-form-item label="备用字段5" prop="weatherForecastExtra5">
          <el-input v-model="form.weatherForecastExtra5" placeholder="请输入备用字段5" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listForecast, getForecast, delForecast, addForecast, updateForecast } from "@/api/business/forecast";

export default {
  name: "Forecast",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预报天气表格数据
      forecastList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        province: null,
        city: null,
        adcode: null,
        date: null,
        week: null,
        dayWeather: null,
        dayWeatherImg: null,
        nightWeather: null,
        nightWeatherImg: null,
        dayTemp: null,
        nightTemp: null,
        dayWind: null,
        nightWind: null,
        dayPower: null,
        nightPower: null,
        reportTime: null,
        weatherForecastExtra1: null,
        weatherForecastExtra2: null,
        weatherForecastExtra3: null,
        weatherForecastExtra4: null,
        weatherForecastExtra5: null,
        createId: null,
        createName: null,
        updateId: null,
        updateName: null,
        accountId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预报天气列表 */
    getList() {
      this.loading = true;
      listForecast(this.queryParams).then(response => {
        this.forecastList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        province: null,
        city: null,
        adcode: null,
        date: null,
        week: null,
        dayWeather: null,
        dayWeatherImg: null,
        nightWeather: null,
        nightWeatherImg: null,
        dayTemp: null,
        nightTemp: null,
        dayWind: null,
        nightWind: null,
        dayPower: null,
        nightPower: null,
        reportTime: null,
        weatherForecastExtra1: null,
        weatherForecastExtra2: null,
        weatherForecastExtra3: null,
        weatherForecastExtra4: null,
        weatherForecastExtra5: null,
        createId: null,
        createName: null,
        createTime: null,
        updateId: null,
        updateName: null,
        updateTime: null,
        accountId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预报天气";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getForecast(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预报天气";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateForecast(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addForecast(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除预报天气编号为"' + ids + '"的数据项？').then(function() {
        return delForecast(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yanjing/forecast/export', {
        ...this.queryParams
      }, `forecast_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
